/*
 * $Id: sem.h 50 2009-02-10 05:48:05Z hyunghwan.chung $
 *
   Copyright 2005-2009 Chung, Hyung-Hwan.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an  BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

#ifndef _XP_BAS_SEM_H_
#define _XP_BAS_SEM_H_

#include <xp/types.h>
#include <xp/macros.h>

#if defined(_WIN32)
#include <windows.h>
#else
#include <semaphore.h>
#endif

#if defined(_WIN32)
	typedef HANDLE xp_semhnd_t;
#else
	typedef sem_t xp_semhnd_t;
#endif
	
typedef struct xp_sem_t xp_sem_t;

struct xp_sem_t
{
	xp_semhnd_t hnd;
	xp_bool_t __dynamic;
};

#ifdef __cplusplus
extern "C" {
#endif

xp_sem_t* xp_sem_open (xp_sem_t* sem, unsigned int init);
int xp_sem_close (xp_sem_t* sem);

int xp_sem_acquire (xp_sem_t* sem);
int xp_sem_release (xp_sem_t* sem);

#ifdef __cplusplus
}
#endif

#endif
